﻿@using TomNet.IMSC.Model.DbModels.Organization
@{
    Layout = null;
    var sentity = ViewBag.sentity as SelectList;
    var entity = ViewData["entity"] as Staff;
}

<!DOCTYPE html>

<html>
<head>
	<meta name="viewport" content="width=device-width" />
	<link href="~/Content/Css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
	<link href="~/Content/Css/font-awesome.css?v=4.4.0" rel="stylesheet">
	<link href="~/Content/Css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
	<link href="~/Content/Css/animate.css" rel="stylesheet">
	<link href="~/Content/Css/style.css?v=4.1.0" rel="stylesheet">
	<link href="~/Content/Css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="~/Content/Common.css" rel="stylesheet" />
    <link href="~/Content/Css/plugins/multiselect/bootstrap-multiselect.css" rel="stylesheet" />
	<title>Insert</title>
	<style type="text/css">
		.i-checks { padding-left:15px;}
        
        .ibox {
            margin-bottom: 0px;
        }
            

        .multiselect-container input[type="checkbox"] {
            margin-top: 7px;
        }
        .pull-left {
            padding-left:0px;
        } 
        #BZid {
            width:92px;
        }
        #BZinput { 
            padding-right:0px;
            width:620px;
        }
        /*.col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12,
        .col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12,
        .btn-group,div {
            border-style: solid;
            border-width: 1px;
            border-color: #000;
        }*/
	</style>
</head>
<body>
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="col-xs-12">
			<form class="form-horizontal m-t" id="mainForm">
				<input type="hidden" id="Id" name="Id" value="@entity.Id" />
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="col-xs-3 control-label">姓名：</label>
							<div class="col-xs-8">
								<input id="Name" name="Name" type="text" class="form-control" value="@entity.Name">
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="col-xs-3 control-label">性别：</label>
							<div class="col-xs-8 radio i-checks">
								<label><input type="radio" name="Sex" value="1" @Html.Raw(entity.Sex == 1 ? "checked=\"checked\"" : "")>男</label>
								&nbsp;&nbsp;&nbsp;&nbsp;
								<label><input type="radio" name="Sex" value="2" @Html.Raw(entity.Sex == 2 ? "checked=\"checked\"" : "")>女</label>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="col-xs-3 control-label">电话：</label>
							<div class="col-xs-8">
								<input id="Phone" name="Phone" type="text" class="form-control" value="@entity.Phone">
							</div>
						</div>
					</div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="col-xs-3 control-label">部门：</label>
                            <div class="col-xs-8">
                                @Html.DropDownList("DepartmentId", (SelectList)ViewBag.selectDepartment, new { @class = "form-control m-b" })
                            </div>
                        </div>
                    </div>
                    @*<div class="col-xs-6">
                        <div class="form-group">
                            <label class="col-xs-3 control-label">角色：</label>
                            <div class="col-xs-8">
                                <select id="RoleId" class="form-control input-sm" name="RoleId" multiple="multiple"></select>
                            </div>
                        </div>
                    </div>*@ 
				</div> 
                <div class="row"> 
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="col-xs-3 control-label">考勤规则：</label>
                            <div class="col-xs-8">
                                <select class="form-control" name="SideModuleID" id="SideModuleID">
                                    <option value=''>-请选择-</option>
                                    @foreach (SelectListItem item in sentity.Items)
                                    {
                                        <option value='@item.Value' @(entity.SideModuleID == Convert.ToInt32(item.Value)?"selected":"")>@(item.Text)</option>
                                    }
                                </select>
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请选择考勤规则</span>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="col-xs-3 control-label">代理：</label>
                            <div class="col-xs-8">
                                @Html.DropDownList("AgentId", (SelectList)ViewBag.selectAgent, new { @class = "form-control m-b" })
                            </div>
                        </div>
                    </div>
                </div>

                <div class="row">
                    @*<div class="col-xs-6">
                        <div class="form-group">
                            <label class="col-xs-3 control-label">备注：</label>
                            <div class="col-xs-8">
                                <input id="Remark" name="Remark" type="text" class="form-control" value="@entity.Remark">
                            </div>
                        </div>
                    </div>*@
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="col-xs-2 control-label" id="BZid">备注：</label>
                            <div class="col-xs-10" id="BZinput">
                                <input id="Remark" name="Remark" type="text" class="form-control" value="@entity.Remark">
                            </div>
                        </div>
                    </div>
                </div> 
				<div class="form-group Submit">
					<button id="submit" class="btn btn-primary pull-right" type="submit">
						<i class="fa fa-check"></i>&nbsp;提&nbsp;交
					</button>
				</div>
			</form>
		</div>
	</div>
	<!-- 全局js -->
	<script type="text/javascript" src="~/Scripts/jquery.min.js?v=2.1.4"></script>
	<script type="text/javascript" src="~/Scripts/bootstrap.min.js?v=3.3.6"></script>
	<script type="text/javascript" src="~/Scripts/plugins/iCheck/icheck.min.js"></script>
	<!-- jQuery Validation plugin javascript-->
	<script type="text/javascript" src="~/Scripts/plugins/validate/jquery.validate.min.js"></script>
	<script type="text/javascript" src="~/Scripts/plugins/validate/messages_zh.min.js"></script>
	<script type="text/javascript" src="~/Scripts/Extensions/ExtValidator.js"></script>
	<!-- layer javascript -->
	<script type="text/javascript" src="~/Scripts/plugins/layer/layer.min.js"></script>
    <script src="~/Scripts/plugins/multiselect/bootstrap-multiselect.js"></script>

	<script>
		$('.i-checks').iCheck({
			radioClass: 'iradio_square-green',
		});

		$(function () {
		    GetRole(@entity.Id);
		    $('#RoleId').multiselect({
		        buttonClass: 'btn btn-link',//显示按钮style
		        buttonWidth: '220px',//按钮宽度
		        inheritClass: true,//继承原来select的button的class
		        selectAllNumber: false,//true显示allselect（6）,false显示allselect
		    });
            // validate signup form on keyup and submit
            var icon = "<i class='fa fa-times-circle'></i> ";
            var validator = $("#mainForm").validate({
            	rules: {
            		Name: { required: true, minlength: 2 }
            	},
                messages: {
                    Name: {
                        required: icon + "请输入姓名",
                        minlength: icon + "姓名不少于两个文字"
                    }
                },
                submitHandler: function (form) {
                    //进行ajax传值
                    $.ajax({
                        url: "/organization/staff/editasync",
                        type: "post",
                        dataType: "json",
                        data: $('#mainForm').serialize(),
                        success: function (data) {
                            //Info,Success,Warning,Error
                            var type = data.type;
                            if (type == 1) {
                                layer.msg(data.content, { icon: 6, time: 2000 },
                                    function () {
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                    });

                            } else {
                                layer.msg(data.content, { icon: 5, time: 2000 });
                            }
                        }
                    });
                }
            });
        });

        //$('#testBtn').click(function (e) {
        //    parent.layer.open({
        //        type: 2,
        //        title: '选择角色',
        //        shadeClose: false,
        //        shade: 0.4,
        //        area: ['800px', '500px'],
        //        content: '/Role/Test',
        //        end: function () {
        //            console.info(parent.selectedId);
        //            $('#Name').val(parent.selectedId);
        //        }
        //    });
        //});
        function GetRole(id) {
            console.log(id);
            $.getJSON(
                "/Organization/Staff/GetRole",
                {
                    did: id
                },
                function (data) {
                    console.log(data);
                    $("#RoleId").find("option").remove();
                    $("#RoleId").multiselect("destroy").multiselect({
                        buttonClass: 'btn btn-link',//显示按钮style
                        buttonWidth: '220px',//按钮宽度
                        inheritClass: true,//继承原来select的button的class
                        selectAllNumber: false,//true显示allselect（6）,false显示allselec
                    });
                    $.each(data, function (i, item) {
                        if (item["number"] > 0) {
                            $("<option></option>").val(item["id"]).text(item["name"]).attr("selected", true).appendTo($("#RoleId"));


                            $("#RoleId").multiselect("destroy").multiselect({
                                buttonClass: 'btn btn-link',//显示按钮style
                                buttonWidth: '220px',//按钮宽度
                                inheritClass: true,//继承原来select的button的class
                                selectAllNumber: false,//true显示allselect（6）,false显示allselec
                            });
                        }
                        else {
                            $("<option></option>").val(item["id"]).text(item["name"]).appendTo($("#RoleId"));


                            $("#RoleId").multiselect("destroy").multiselect({
                                buttonClass: 'btn btn-link',//显示按钮style
                                buttonWidth: '220px',//按钮宽度
                                inheritClass: true,//继承原来select的button的class
                                selectAllNumber: false,//true显示allselect（6）,false显示allselec
                            });
                        }


                    });
                });
        }
	</script>
</body>
</html>
